<template>
    <div>
        <h2>欢迎亲的登录</h2>
        <p>
            用户名:<input type="text" v-model="username" />
        </p>
        <p>
            密码:<input type="password" v-model="userpass" />
        </p>
        <p>
            <input type="button" value="登录" @click="loginCheck" />
        </p>
    </div>
</template>

<script>

import axios from "axios";

export default {
    name:"Reg",
    data(){
        return {
            username:"杨智超",
            userpass:"123456"
        }
    },
    methods:{
        loginCheck(){

            // 2、发送请求
            let str = {
                username:this.username,
                userpass:this.userpass
            }
            axios({
                url:"/loginCheck",
                method:"post",
                data:str
            })
            .then(res=>{           
                console.log("res.data",res.data);
                if(res.data.status=='success'){

                    
                    // 登录成功！，需要保存token;
                    localStorage.setItem("token",res.data.token);


                    console.log("登录成功");
                }
            })
            .catch(err=>{
                console.log("出错了",err);
            })
        }
    }
}
</script>

<style scoped>

</style>

